package cn.gok.client.service.impl;

import cn.gok.common.dao.adress.AreaDao;
import cn.gok.common.dao.adress.CityDao;
import cn.gok.common.dao.adress.ProvinceDao;
import cn.gok.common.entity.adress.Area;
import cn.gok.common.entity.adress.City;
import cn.gok.common.entity.adress.Province;
import cn.gok.client.service.AdressSercice;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author shikundai
 * @Date 2020/10/20
 * @Time 16:32
 * @description
 */
@Service
public class AdressServiceImpl implements AdressSercice {
    @Autowired
    private ProvinceDao provinceDao;
    @Autowired
    private CityDao cityDao;
    @Autowired
    private AreaDao areaDao;


    @Transactional(readOnly = true)
    @Override
    public List<Province> getAllProvince() {
        /*
         * 不传查询条件，查询所有的省份
         * */
        List<Province> provinces = provinceDao.selectList(null);
        return provinces;
    }

    @Transactional(readOnly = true)
    @Override
    public Province getProvince(String provinceId) {
        /*
        * 构造条件，通过省份ID查询省份信息
        * */
        QueryWrapper<Province> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("provinceid",provinceId);
        //查询数据
        Province province=provinceDao.selectOne(queryWrapper);
        return province;
    }

    @Transactional(readOnly = true)
    @Override
    public List<City> getCityByProvinceId(String provinceId) {
        /*
         * 构造条件,通过省份ID获得对应的城市
         * */
        QueryWrapper<City> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("provinceid", provinceId);
        //查询数据
        List<City> cities = cityDao.selectList(queryWrapper);
        return cities;
    }

    @Transactional(readOnly = true)
    @Override
    public City getCity(String cityId) {
        /*
        * 构造条件通过城市ID查询城市信息
        * */
        QueryWrapper<City> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("cityid",cityId);
        //查询数据
        City city=cityDao.selectOne(queryWrapper);
        return city;
    }

    @Transactional(readOnly = true)
    @Override
    public List<Area> getAreaByCityId(String cityId) {
        /*
         * 构造条件，通过城市ID获取对应的区域
         * */
        QueryWrapper<Area> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("cityid", cityId);
        //查询数据
        List<Area> areas = areaDao.selectList(queryWrapper);
        return areas;
    }

    @Transactional(readOnly = true)
    @Override
    public Area getArea(String areaId) {
        /*
        * 构造条件，通过区域ID查询区域信息
        * */
        QueryWrapper<Area> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("areaid",areaId);
        //查询数据
        Area area=areaDao.selectOne(queryWrapper);
        return area;
    }
}
